package com.sskj.hhrt;

import android.app.Application;
import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.LifecycleRegistry;
import android.support.annotation.NonNull;
import android.support.multidex.MultiDexApplication;

import com.hjq.toast.ToastUtils;
import com.hjq.toast.style.ToastQQStyle;
import com.sskj.base.utils.SPUtils;
import com.sskj.hhrt.main.MainActivity;
import com.zxy.recovery.core.Recovery;

public class MyApplication extends MultiDexApplication implements LifecycleOwner {
    public static String session;
    public static String account;
    public static String token;
    public static MyApplication instance;
    private LifecycleRegistry mLifecycleRegistry = new LifecycleRegistry(this);

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        mLifecycleRegistry = new LifecycleRegistry(this);
        mLifecycleRegistry.markState(Lifecycle.State.RESUMED);
        ToastUtils.initStyle(new ToastQQStyle());
        ToastUtils.init(this);
        Recovery.getInstance()
                .debug(true)
                .recoverInBackground(false)
                .recoverStack(true)
                .mainPage(MainActivity.class)
                .recoverEnabled(true)
                .callback(null)
                .silent(false, Recovery.SilentMode.RECOVER_ACTIVITY_STACK)
                .init(this);
    }

    public static String getSession() {
        if (session == null) {
            session = (String) SPUtils.get(instance, "session", "");
        }
        return session;
    }
    public static String getToken() {
        if (token == null) {
            token = (String) SPUtils.get(instance, "token", "");
        }
        return token;
    }
    public static String getAccount() {
        if (account == null) {
            account = (String) SPUtils.get(instance, "account", "");
        }
        return account;
    }

    @NonNull
    @Override
    public Lifecycle getLifecycle() {
        return mLifecycleRegistry;
    }
}
